/*
 * meituan.com Inc.
 * Copyright (c) 2010-2018 All Rights Reserved.
 */
package iqiyi;

import java.util.Scanner;

/**
 * <p>
 *
 * </p>
 * @author LvJing
 * @version $Id:MyTest1.java v1.0 2018/9/15 上午10:31 LvJing Exp $
 */
public class MyTest1 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String inputStr = scanner.next();

        if (inputStr == null || inputStr.length() != 6)
            return;

        int front = 0;
        int end = 0;
        for (int i = 0; i < 3; i++) {
            char c = inputStr.charAt(i);
            front = front + (int)c;
        }
        for (int i = 3; i < 6; i++) {
            char c = inputStr.charAt(i);
            end = end + (int)c;
        }

        if (front == end) {
            System.out.println(0);
            return;
        }

        int count = 0;
        if (front < end) {
            byte[] bytes = inputStr.substring(0, 3).getBytes();
            int[] frontArr = {bytes[0], bytes[1], bytes[2]};
            int min = frontArr[0];
            int minPos = 0;
            count++;
            for (int i = 1; i < 3; i++) {
                if (min > frontArr[i]) {
                    min = frontArr[i];
                    minPos = i;
                }
            }
            int compare = end - (front - min);
            if (compare <= 9)
                System.out.println(1);
            if (compare > 9) {
                int[] newFrontArr = new int[2];
                int pos = 0;
                for (int i = 0; i < 3 && i != minPos; i++) {
                    newFrontArr[pos++] = frontArr[i];
                }
                count++;
                int min2 = 0;
                if (newFrontArr[0] < newFrontArr[1])
                    min2 = newFrontArr[0];
                else
                    min2 = newFrontArr[1];
                compare = end - ((front - min) + 9 - min2);
                if (compare > 9)
                    System.out.println(3);
                else
                    System.out.println(2);
            }
        } else {
            byte[] bytes = inputStr.substring(3).getBytes();
            int[] frontArr = {bytes[0], bytes[1], bytes[2]};
            int min = frontArr[0];
            int minPos = 0;
            count++;
            for (int i = 1; i < 3; i++) {
                if (min > frontArr[i]) {
                    min = frontArr[i];
                    minPos = i;
                }
            }
            int compare = front - (end - min);
            if (compare <= 9)
                System.out.println(1);
            if (compare > 9) {
                int[] newFrontArr = new int[2];
                int pos = 0;
                for (int i = 0; i < 3 && i != minPos; i++) {
                    newFrontArr[pos++] = frontArr[i];
                }
                count++;
                int min2 = 0;
                if (newFrontArr[0] < newFrontArr[1])
                    min2 = newFrontArr[0];
                else
                    min2 = newFrontArr[1];
                compare = front - ((end - min) + 9 - min2);
                if (compare > 9)
                    System.out.println(3);
                else
                    System.out.println(2);
            }
        }
    }
}
